package com.blinddate.dao;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.blinddate.orm.BdUser;

public class BaseDAOImpl extends HibernateDaoSupport implements BaseDAO {

	@Override
	public void addBdUser(BdUser u) {
		HibernateTemplate template = getHibernateTemplate();
		template.save(u);

	}

	@Override
	public BdUser getBdUser(int id) {
		BdUser u = (BdUser)getHibernateTemplate().get(BdUser.class, id);
		return u;
	}

	@Override
	public List listBuUser() {
		return getHibernateTemplate().find("from BdUser");
	}

	@Override
	public void updateBdUser(BdUser u) {
		getHibernateTemplate().update(u);

	}

	@Override
	public void deleteBdUser(int id) {
		BdUser u = (BdUser)getHibernateTemplate().get(BdUser.class, id);
		getHibernateTemplate().delete(u);
	}
	
	@Override
	public Object loadObject(String hql) {
		final String hql1 = hql;
		Object obj = null;
		List list = getHibernateTemplate().executeFind(new HibernateCallback(){
			public Object doInHibernate(Session session) throws HibernateException{
				Query query = session.createQuery(hql1);
				return query.list();
			}
		});			
		if(list.size()>0)obj=list.get(0);	
		return obj;
	}


}
